package com.ukao.cashregister.adapter;

import android.content.Context;
import android.view.View;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.listener.OnItemClickListener;
import com.ukao.cashregister.widget.StateButton;
import com.ukao.cashregister.widget.StateImageView;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class KeyboardAdapter extends CommonAdapter<String> {



    private OnItemClickListener mOnClickListener;
    private   boolean  isVipEnter;
    public KeyboardAdapter(Context context, List<String> datas) {
        super(context, datas, R.layout.adapter_key_board);
    }


    public   void  setIsVipEnter(boolean  isVipEnter){
        this.isVipEnter=isVipEnter;
    }

    public  void  setOnClickListener(OnItemClickListener mOnClickListener){
        this.mOnClickListener=mOnClickListener;

    }


    @Override
    public void convert(final  ViewHolder viewHolder,final String item) {
        StateButton  mStateButton=(StateButton)viewHolder.getView(R.id.ket_button);
        StateImageView mImageButton=(StateImageView)viewHolder.getView(R.id.ket_Image_button);


        mStateButton.setText(item);
     final    int  position=viewHolder.getLayoutPosition();
        mStateButton.setVisibility(View.VISIBLE);
        mImageButton.setVisibility(View.GONE);
        if (isVipEnter){
            switch (position){
                case  10:
                    mStateButton.setVisibility(View.GONE);
                    mImageButton.setVisibility(View.VISIBLE);
                break;
                case  11:
                    mStateButton.setTextColor(mContext.getResources().getColor(R.color.white));
                    mStateButton.setNormalBackgroundColor(mContext.getResources().getColor(R.color.blue));
                    mStateButton.setPressedBackgroundColor(mContext.getResources().getColor(R.color.default_blue));
                    break;
            }
        }
        mImageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickListener!=null){
                        int  position=viewHolder.getLayoutPosition();
                    mOnClickListener.onSureItemClick(     getItem(position),position);
                }


            }
        });

        mStateButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnClickListener!=null){
                    int  position=viewHolder.getLayoutPosition();
                    mOnClickListener.onSureItemClick(     getItem(position),position);
                }
            }
        });
    }






}
